package com.mall.web.controller.product;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.StringUtils;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.product.domain.biz.ProCustomRecordValueBiz;
import com.mall.product.domain.entity.ProCustomRecordValue;
import com.mall.product.service.ProCustomRecordService;
import com.mall.product.service.ProCustomRecordValueService;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 商品自定义档案值Controller
 *
 * @author zhonglin
 * @date 2020-05-07
 */
@Controller
@RequestMapping("/product/customRecordValue")
public class ProCustomRecordValueController
    extends BaseController {

  private String prefix = "product/customRecordValue";

  @Autowired
  private ProCustomRecordValueService proCustomRecordValueService;

  @Autowired
  private ProCustomRecordService proCustomRecordService;

  @RequiresPermissions("product:customRecordValue:view")
  @GetMapping()
  public String customRecordValue() {

    return prefix + "/customRecordValue";
  }

  /**
   * 查询商品自定义档案值列表
   */
  @RequiresPermissions("product:customRecordValue:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(ProCustomRecordValue proCustomRecordValue) {

    startPage();
    List<ProCustomRecordValueBiz> list = proCustomRecordValueService.selectProCustomRecordValueList(proCustomRecordValue);
    return getDataTable(list);
  }

  /**
   * 导出商品自定义档案值列表
   */
  @RequiresPermissions("product:customRecordValue:export")
  @Log(title = "商品自定义档案值", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(ProCustomRecordValue proCustomRecordValue) {

    List<ProCustomRecordValueBiz>      list = proCustomRecordValueService.selectProCustomRecordValueList(proCustomRecordValue);
    ExcelUtil<ProCustomRecordValueBiz> util = new ExcelUtil<ProCustomRecordValueBiz>(ProCustomRecordValueBiz.class);
    return util.exportExcel(list, "customRecordValue");
  }

  /**
   * 新增商品自定义档案值
   */
  @GetMapping(value = {"/add/{customRecordId}", "/add"})
  public String add(@PathVariable(value = "customRecordId", required = false) Long customRecordId,
                    ModelMap mmap) {

    if (StringUtils.isNotNull(customRecordId)) {
      mmap.put("customRecord", proCustomRecordService.selectProCustomRecordById(customRecordId));
    }
    return prefix + "/add";
  }

  /**
   * 新增保存商品自定义档案值
   */
  @RequiresPermissions("product:customRecordValue:add")
  @Log(title = "商品自定义档案值", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(ProCustomRecordValue proCustomRecordValue) {

    return toAjax(proCustomRecordValueService.insertProCustomRecordValue(proCustomRecordValue));
  }

  /**
   * 修改商品自定义档案值
   */
  @GetMapping("/edit/{customRecordValueId}")
  public String edit(@PathVariable("customRecordValueId") Long customRecordValueId,
                     ModelMap mmap) {

    ProCustomRecordValueBiz proCustomRecordValue = proCustomRecordValueService.selectProCustomRecordValueById(customRecordValueId);
    mmap.put("proCustomRecordValue", proCustomRecordValue);
    return prefix + "/edit";
  }

  /**
   * 修改保存商品自定义档案值
   */
  @RequiresPermissions("product:customRecordValue:edit")
  @Log(title = "商品自定义档案值", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(ProCustomRecordValue proCustomRecordValue) {

    return toAjax(proCustomRecordValueService.updateProCustomRecordValue(proCustomRecordValue));
  }

  /**
   * 删除商品自定义档案值
   */
  @RequiresPermissions("product:customRecordValue:remove")
  @Log(title = "商品自定义档案值", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {

    return toAjax(proCustomRecordValueService.deleteProCustomRecordValueByIds(ids));
  }

}
